package app.dev.ems.web.wicket.page;

import java.lang.reflect.InvocationTargetException;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.protocol.https.RequireHttps;

import app.dev.ems.web.element.NavigationStatus;
import app.dev.ems.web.element.menu.MenuElement;
import app.dev.ems.web.element.page.BasePageElement;
import app.dev.ems.web.wicket.application.EMSApplication;
import app.dev.ems.web.wicket.factory.NavigationLinkFactory;
import app.dev.ems.web.wicket.panel.menu.vertical.BaseVerticalMenuPanel;
import app.dev.ems.web.wicket.session.EMSSession;

@RequireHttps
public abstract class BasePage extends WebPage implements AuthenticatedWebPage {

	private static final long serialVersionUID = -5479935743833270108L;
		
	public BasePage(NavigationStatus activeHorizontalNavigationStatus, NavigationStatus activeVerticalNavigationStatus, Class<? extends BaseVerticalMenuPanel> verticalMenuPanel) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {				
		final EMSSession session = getSession();
		session.setActiveHorizontalNavigationStatus(activeHorizontalNavigationStatus);
		session.setActiveVerticalNavigationStatus(activeVerticalNavigationStatus);
		
		add(new Label(BasePageElement.HEAD_TITLE.getElement(), new PropertyModel<String>(this, BasePageElement.HEAD_TITLE.getElement())));
		add(new Label(BasePageElement.PAGE_TITLE.getElement(), new PropertyModel<String>(this, BasePageElement.PAGE_TITLE.getElement())));		
		add(verticalMenuPanel.getConstructor(new Class[] {String.class}).newInstance(MenuElement.VERTICAL_NAVIGATION.getElement()));		
		add(NavigationLinkFactory.INSTANCE.getLogoutLink());
		add(NavigationLinkFactory.INSTANCE.getAdministrationLink());
	}
	
	public EMSApplication getEMSApplication(){
		return EMSApplication.getInstance();
	}
	
	@Override
	public EMSSession getSession() {
		return (EMSSession) super.getSession();
	}
	
	public abstract String getTitle();

	public String getHeadTitle() {
		return getTitle();
	}

	public String getPageTitle() {
		return getTitle();
	}
}
